// Product detail page
// ===================

define(['zepto', 'utils', 'wxshare'], function($, utils, wxshare) {
  return {
    init: function(data) {
      
      this.onClickGoTopButton()
      
      // open wxchart share with shareData
      var shareData = this.initShareData(utils.parseJSON(data.productData))
      wxshare.initShare(utils.parseJSON(data.jsConfig), true, shareData)

      // TIPS: example how can we disable wxchart share 
      //wxshare.initShare(utils.parseJSON(data.jsConfig), false)
    },
    
    initShareData: function(product) {
      return {
        title:  product.name,
        desc:   product.summary,
        link:   window.__CTX__.root + "/products/" + product.id + "/view",
        imgUtl: product.cover,
        id:     product.id
      }
    },

    /**
     * Handler fired on clicking the 'Go Top' button
     */
    onClickGoTopButton: function() {
      var content = document.querySelector('.content')
      $('.button-up').on('click', function(e) {
        e.preventDefault()
        content.scrollTop = 0
      })
    }
  }
})